#ifndef _OUTPUT_H__
#define _OUTPUT_H__


#include <vector>
#include "vtkUnstructuredGrid.h"
#include "save_cells.h"


class Mesh;

class OutputData
{
 public:
  OutputData(std::string _name, int _type);
  void addComponent(double *_data);
  ~OutputData();
  
 protected:
  std::string name;
  int type;
  std::vector<double*> data;
  
  friend class Output;
};


class Output
{
 public:
  Output(Mesh *_mesh, const char *_savebase, SaveCells _cells);
  ~Output();
  
  int registerNodeData(std::string _name, int _type);
  
  int registerAndAllocateNodeData(std::string _name, int _type, int size);
  
  void addComponent(int data_id, double *_data);
  
  int size();
  
  bool saveCells(SaveCells _cells) { return (cells & _cells); };

  /**
    Save solution in VTK format.
    @param index Index appended to the file name (-1 = no index appended).
  */
  void saveVTK(int index = -1);
  
  /**
    Save solution in Gnuplot datafile format.
    @param file File name.
  */
  void saveGnuplot(const char *file = 0);
  
 private:
  Mesh *mesh;        /**< Associated mesh. */
  std::vector<OutputData*> data;
  SaveCells cells;
  const char *savebase;

  vtkUnstructuredGrid *ug;
};






#endif
